package com.example.server.controller.admin;

import com.example.server.common.config.annotation.MustLogin;
import com.example.server.common.config.auth.TokenUser;
import com.example.server.common.constant.Result;
import com.example.server.entity.Sword;
import com.example.server.service.admin.SwordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * @author china.fuyao@outlook.com
 * @date 2020-04-20 17:17
 */
@Api(tags = "Admin敏感词相关接口")
@RestController
@RequestMapping("/admin/sword")
public class AdminSwordController {
    @Resource
    SwordService swordService;

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "新增敏感词", notes = "新增敏感词")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "敏感词", name = "sword", required = true)
    })
    @PostMapping("/add")
    public Result addSword(String sword, @ApiIgnore TokenUser tokenUser) {
        return swordService.addSword(sword, tokenUser.getCustomerId());
    }


    @MustLogin(isAdmin = true)
    @ApiOperation(value = "更新敏感词", notes = "更新敏感词")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "敏感词Id", name = "swordId", required = true),
            @ApiImplicitParam(value = "敏感词", name = "sword", required = true)
    })
    @PostMapping("/update")
    public Result updateSword(Integer swordId,String sword, @ApiIgnore TokenUser tokenUser) {
        return swordService.updateSword(swordId,sword, tokenUser.getCustomerId());
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "批量删除敏感词", notes = "批量删除敏感词")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "敏感词", name = "swordIds", required = true)
    })
    @PostMapping("/batchDel")
    public Result batchDelSword(String swordIds, @ApiIgnore TokenUser tokenUser) {
        return swordService.batchDelSword(swordIds, tokenUser.getCustomerId());
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "敏感词列表", notes = "获取所有敏感词")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "page", required = true),
            @ApiImplicitParam(value = "数量", name = "limit", required = true),
            @ApiImplicitParam(value = "敏感词", name = "sword", required = false)
    })
    @GetMapping("/list")
    public Result swordList(Integer page, Integer limit, String sword, @ApiIgnore TokenUser tokenUser) {
        return swordService.swordList(page, limit, sword, tokenUser.getCustomerId());
    }
}